<?php
/**
 *  站点设置控制器
 */
namespace app\admin\controller;
use app\admin\model\Site as SiteModel;
use app\admin\model\Config as ConfigModel;

class Site extends Common
{
	private $model;
	private $modelc;
    public function _initialize()
    {
		parent::_initialize();
        $this->modelc = new ConfigModel();
		$this->model = new SiteModel();
    }

    // 显示站点信息
    public function index()
    {
        // 获取主题列表
		//$themes =dir_list(ROOT_PATH.'app'.DS. current($this->tpl_dir));
        //$this->assign('themes', $themes);
        //获取系统配置
        $this->assign('sites', $this->model->getList());
		$this->assign('configs',get_cache('config'));
        //显示
		return $this->fetch();
    }

    // 修改站点信息
    public function mod()
    {
        if(!$this->request->isPost()) {
            return;
        }
        $UrlParam=input();
        $data = array(
            'title' => $UrlParam['title'],
            'subtitle' => $UrlParam['subtitle'],
			'htmc' => $UrlParam['htmc'],
            'domain' => $UrlParam['domain'],
            'logo' => $UrlParam['logo'],
			//'logoico' => $UrlParam['logoico'],
            'keywords' => $UrlParam['keywords'],
            'description' => $UrlParam['description'],
            'icp' => $UrlParam['icp'],
            //'theme' => basename($UrlParam['theme']) ?: 'default',
			//'themese' => basename($UrlParam['themese']) ?: '0',
            'statistical' => $UrlParam['statistical'],
            'copyright' => $UrlParam['copyright']
        );
		path_delete(RUNTIME_PATH . '/config'); // 清理缓存的配置文件
		if ($this->model->modSite($data)) {
			$this->success('修改成功！');
		} else {
			$this->error('修改失败！');
		}
    }
    // 服务器基础信息
    public function server()
    {
        $this->assign('server', get_server_info());
		return $this->fetch();
    }
	 // 应用配置列表
    public function modzf()
    {
        // 修改参数配置
        if($this->request->isPost()) {
			$Post=input('post.');
			unset($Post['submit']);
			$this->ClearingSave($Post);
        }
		return $this->fetch();
    }
	private function ClearingSave($Post)
    {
        $Str='<?php'."\r\n";
        $Str.='return ';
        $Str.=var_export($Post,true);
        $Str.=';';
        file_put_contents(APP_PATH.'extra/systemparam.php',$Str);
        $this->success('修改成功！', url('/Site/index', false));
        exit;
    }
}